<!DOCTYPE html>
<!--[if lt IE 9]><html class="ie no_svg"><![endif]-->
<!--[if IE 9]><html class="ie9"><![endif]-->
<!--[if gt IE 9]><!-->
<html><!--<![endif]--><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta charset="utf-8">
        <title>Tumblr</title>
        <style type="text/css">
            * {
                margin: 0;
                padding: 0;
            }

            html, body {
                width: 100%;
                height: 100%;
            }

            #like_wrapper {
                height: 100%;
                width: 100%;
            }

            #like {
                display: block;
                width: 100%;
                height: 100%;
                cursor: default;
            }

            #like svg {
                fill: #ccc;
            }

            .white #like svg {
                fill: #fff;
            }

            .black #like svg {
                fill: #000;
            }

            #like.liked svg {
                fill: #d75f45;
            }

            #like.show {
                opacity: 1;
            }

            .no_svg #like {
                filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/iframe_like_big_default.png', sizingMethod='scale');
            }

            .no_svg .white #like {
                filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/iframe_like_big_white.png', sizingMethod='scale');
            }

            .no_svg .black #like {
                filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/iframe_like_big_black.png', sizingMethod='scale');
            }

            .no_svg #like.liked {
                filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/iframe_like_big_red.png', sizingMethod='scale');
            }
        </style>
    </head>
    <body>
        <div id="like_wrapper" class="black">
            <a href="https://www.tumblr.com/register?redirect_to=http%3A%2F%2Fnadievstodos.tumblr.com%2Fpost%2F147151140760%2Ft2x03-project-executive-doc" id="like" target="_top" onclick="return false;" style="cursor: pointer;" class="show">
                <svg width="100%" height="100%" viewBox="0 0 19 16" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" fill="#000000"><path d="M14.0425097,0.000920262799 C16.1435097,-0.0400797372 18.8835097,1.28192026 18.9635097,5.36992026 C19.0525097,9.95492026 15.1985097,13.3079203 9.48350967,16.2089203 C3.76650967,13.3079203 -0.0874903349,9.95492026 0.00150966509,5.36992026 C0.0815096651,1.28192026 2.82150967,-0.0400797372 4.92250967,0.000920262799 C7.02450967,0.0419202628 8.87050967,2.26592026 9.46950967,2.92792026 C10.0945097,2.26592026 11.9405097,0.0419202628 14.0425097,0.000920262799 Z"></path></svg>
            </a>
        </div>
        <script type="text/javascript">
            var state = '';
            var form_key = '';
            var post_id = '';
            var reblog_key = '';
            var root_id = '';
            var like = document.getElementById('like');

            function is_logged_in() {
                return (document.cookie.indexOf('logged_in=1') != -1);
            }

            function setup_listener(callback){
                callback = callback || function(){};
                // http://davidwalsh.name/window-iframe
                // Create IE + others compatible event handler
                var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
                var eventer = window[eventMethod];
                var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
                // Listen to message from child window
                eventer(messageEvent,function(e) {
                    var message = e.data.split(';');
                    callback(message, e.origin);
                },false);
            }

            function getVars() {
                var get_vars = {};
                window.location.hash.replace(
                    /[#?&]+([^=&]+)(=[^&]*)?/gi,
                    function(m, key, value){
                        get_vars[key] = (value === undefined) ? true : value.substring(1);
                    }
                );

                return get_vars;
            }

            function setup_variables() {
                var vars = getVars();
                if (vars['post_id']) post_id = vars['post_id'];
                if (vars['rk']) reblog_key = vars['rk'];
                if (vars['root_id']) root_id = vars['root_id'];
                if (vars['color']) {
                    if (vars['color'] == 'white') {
                        document.getElementById('like_wrapper').className = 'white';
                    } else if (vars['color'] == 'black') {
                        document.getElementById('like_wrapper').className = 'black';
                    }
                }

            }

            // Transition unload -- Supresses iframe white flash
            window.onbeforeunload = function(){
                if (window !== parent) parent.postMessage('location_change' + ';' + document.location.protocol + '//' + document.location.host,
                    document.referrer);
            };

            function like_post() {
                var action = (state === 'liked') ? 'unlike' : 'like';
                var data = action + ';' + JSON.stringify({post_id: post_id, reblog_key: reblog_key, root_id: root_id});
                var iframe_count = window.parent.frames.length;

                for (var i = 0; i<iframe_count; i++) {
                    try {
                        if (window.parent.frames[i] !== window) window.parent.frames[i].postMessage(data, '*');
                    } catch (e) {
                        // do nothing
                    }
                }
            }

            function update_status() {
                like.className = (state === 'liked') ? 'show liked' : 'show';
                var msg = "tumblelog_like;" + post_id + ";" + state;
                window.parent.postMessage(msg, document.referrer);
            }

            function setup_state() {
                like.style.cursor = "pointer";
                like.onclick = function(e) {
                    like_post();
                    return false;
                }
                update_status();
            }

            function recieve_data(message, origin) {
                if (message[0] === "state_update") {
                    var data = JSON.parse(message[1]);
                    if (typeof(data) === "object") {
                        if (data.length) {
                            data.forEach(function(d) {
                                // Doing a non-strict check on ids, this is on
                                // purpose because sometimes it appears to return
                                // a string and not a number.
                                if (d.post_id == post_id) {
                                    state = (d.state) ? 'liked' : 'unliked';
                                    setup_state();
                                }
                            });
                        } else {
                            // Non-strict check.
                            if (data.post_id == post_id) {
                                state = (data.state) ? 'liked' : 'unliked';
                                setup_state();
                            }
                        }
                    }
                }
            }

            window.onload = function() {
                if (post_id) {
                    var data = 'like_iframe_load;' + JSON.stringify({post_id: post_id});
                    window.parent.postMessage(data, '*');
                }
            }

            // Set up variables -- logged out user should still pick up color settings.
            setup_variables();

            // don't setup the click events if they are not logged in
            if (is_logged_in()) {
                setup_listener(recieve_data);
            } else {
                // logged out and doesn't care about state
                var path = (document.cookie.indexOf('logged_in') != -1) ? '/login?' : '/register?';
                like.href = "https://www.tumblr.com" + path + 'redirect_to=' + encodeURIComponent(document.referrer);
                like.onclick = function() { return true; };
                like.style.cursor = "pointer";
                like.className = 'show';
            }
        </script>
    

</body></html>